
const title = {
  pro: '生产商城',
  dev: '开发商城'
}

const externals = {
  vue: 'Vue',
  'element-ui': 'ELEMENT',
  axios: 'axios',
  'vue-router': 'VueRouter',
  echarts: 'echarts',
  'vue-quill-editor': 'quill'
}

const cdn = {
  dev: {
    css: [],
    js: []
  },
  pro: {
    css: [
      'https://cdn.jsdelivr.net/npm/element-ui@2.15.6/lib/theme-chalk/index.css'
    ],
    js: [
      'https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js',
      'https://cdn.jsdelivr.net/npm/element-ui@2.15.6/lib/index.js',
      'https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js',
      'https://unpkg.com/vue-router@3.5.0/dist/vue-router.min.js',
      'https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js'
    ]
  }
}

module.exports = {
  // 关于webpack的一系列配置

  // outputDir: 'dist',
  // publicPath: process.env.NODE_ENV === 'production' ? '/' : './',
  // assetsDir: 'static',
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      // 生产包取消console debugger打印
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
      config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
    }
  },

  chainWebpack: (config) => {
    config.when(process.env.NODE_ENV === 'production', config => {
      // 2. 打包优化  ---  1. 设置入口文件

      config.entry('app').clear().add('./src/main-pro.js')

      config.set('externals', externals)

      // 1.定制生产标题
      config.plugin('html').tap((args) => {
        args[0].cdn = cdn.pro
        // 设置标题
        args[0].title = title.pro
        return args
      })
    })

    config.when(process.env.NODE_ENV === 'development', config => {
      // 定制开发标题
      config.plugin('html').tap((args) => {
        // 开发cdn
        args[0].cdn = cdn.dev
        // 设置标题
        args[0].title = title.dev
        return args
      })
    })
  }
}
